﻿using System.Drawing;
using System.Windows.Forms;
namespace RPG1
{
    abstract public class Role
    {
        private string name;
        private int originalLife; // 原始生命值
        private int currentLife; // 当前生命值 
        private int damage;  // 力量
        private int agile; // 敏捷
        private int brains; // 智力
        private int speed; // 速度
        private Point currentLocation; // 原始位置
        private Point originaLocation ;//  当前位置
        private PictureBox picBox;
        private Label bottomLabel;
        private Label topLabel;
        private Weapon wpn;
        public Role(string name, int originalLife, int currentLife, int damage, int agile, int brains, int speed,
            PictureBox picBox, Label bottomLabel, Label topLabel, Weapon wpn)
        {
            Name = name;
            OriginalLife = originalLife;
            CurrentLife = currentLife;
            Damage = damage;
            Agile = agile;
            Brains = brains;
            Speed = speed;
            PicBox = picBox;
            BottomLabel = bottomLabel;
            TopLabel = topLabel;
            Wpn = wpn ?? throw new System.ArgumentNullException(nameof(wpn));

            CurrentLocation = PicBox.Location;
            OriginaLocation = PicBox.Location;
        }
        public string Name { get => name; set => name = value; }
        public int OriginalLife { get => originalLife; set => originalLife = value; }
        public int CurrentLife { get => currentLife; set => currentLife = value; }
        public int Damage { get => damage; set => damage = value; }
        public int Agile { get => agile; set => agile = value; }
        public int Brains { get => brains; set => brains = value; }
        public Point CurrentLocation { get => currentLocation; set => currentLocation = value; }
        public Point OriginaLocation { get => originaLocation; set => originaLocation = value; }
        public PictureBox PicBox { get => picBox; set => picBox = value; }
        public Label BottomLabel { get => bottomLabel; set => bottomLabel = value; }
        public Label TopLabel { get => topLabel; set => topLabel = value; }
        public Weapon Wpn { get => wpn; set => wpn = value; }
        public int Speed { get => speed; set => speed = value; }

        public void Delay(int times)
        {
            for (int i = 0; i < times; i++)
                Application.DoEvents();
        }

        public abstract int getAttack();
        public abstract int getDefense();
        public abstract void attack(Role role);

        public void bloodLoss(int enemyDamage)
        {
            if(enemyDamage>=0)
                CurrentLife -= enemyDamage;
           
            if (CurrentLife <= 0)
                CurrentLife = 0;
            TopLabel.Width = (int)(1.0*CurrentLife / OriginalLife * BottomLabel.Width);
            //MessageBox.Show(""+1.0*CurrentLife / OriginalLife);
            TopLabel.Text = " " + (1.0 * CurrentLife / OriginalLife * 100)+"%";
            BottomLabel.BringToFront();
            TopLabel.BringToFront();
        }
        public void died()
        {
            TopLabel.Dispose();
            BottomLabel.Dispose();
            PicBox.Dispose();
        }
    }
}
